home *** CD-ROM | disk | FTP | other *** search
- ; ***********************************************************************
- ; * *
- ; * *
- ; * ***** ***** *
- ; * ***** ***** *
- ; * ***** ***** *
- ; * ***** ***** *
- ; * ***** ***** *
- ; * ***** ***** *
- ; * ***** ***** *
- ; * ***** ***** The Firmware. The Net. *
- ; * ***** ***** Portable. Compatible. *
- ; * ***** ***** Public Domain. *
- ; * ***** ***** By NORD><LINK. *
- ; * *
- ; * *
- ; * *
- ; * CRUNTIME.MAC - Z80 C Runtime Library *
- ; * (modifizierte Version des Runtime-Moduls *
- ; * aus dem Q/C-Compilerpaket) *
- ; * *
- ; * *
- ; * angelegt: DC4OX *
- ; * modifiziert: *
- ; * *
- ; ***********************************************************************
-
- ; G8KBB April 1991
- ; This is a much reduced version for an alternative compiler.
- ; It misses out most of the runtime functions.
- ; ALso, function entry/exit changed to preserve IX
-
- ; released as thenet x-1j september 1993
-
- .z80
-
-
- ; +---------------------------------------------------------------------+
- ; | |
- ; | Funktionsstart fuer Parameter, es werden die Stackframepointer |
- ; | (BC/IX) gesetzt, so dass auf Funktionsargumente zugegriffen werden |
- ; | kann. |
- ; | |
- ; | Return : HL - benutzt |
- ; | |
- ; +---------------------------------------------------------------------+
-
- public fentp
- public ?en
-
- fentp:
- ?en: pop HL ; Returnadresse holen
- push IX ; save IX ( G8KBB )
- push BC ; Stackframe-Pointer sichern
- ld IX,0 ; lokaler Stackframe-Pointer, kein Platz
- add IX,SP ; fuer lokale Variablen benoetigt
- push IX ; BC auch Stackframe-Pointer
- pop BC
- jp (HL) ; das war's - weiter an Returnadresse
-
-
-
-
-
- ; +---------------------------------------------------------------------+
- ; | |
- ; | Funktionsstart fuer Parameter/Locals, wie fentp, zusaetzlich wird |
- ; | Platz fuer lokale Variable auf dem Stack geschaffen, Platz in Bytes |
- ; | negativ als Parameter hinter Aufruf (16 Bit). |
- ; | |
- ; | Return : SP - um angeforderten Platz korrigiert |
- ; | BC, IX - neuer Stackframe-Pointer |
- ; | DE, HL - benutzt |
- ; | |
- ; | |
- ; +---------------------------------------------------------------------+
-
- public fentpl
- public ?ens
-
- fentpl:
- ?ens: pop HL ; Adresse Aufrufpar. (angeforderter Platz)
- push IX ; save IX ( G8KBB )
- push BC ; Stackframe-Pointer sichern
- ld E,(HL) ; LSB angeforderter Platz
- inc HL ; Zeiger auf MSB angeforderter Platz
- ld D,(HL) ; MSB angeforderter Platz
- inc HL ; neue Returnadresse hinter Parameter
- ex DE,HL ; Returnadresse <-> angeforderter Platz
- add HL,SP ; Stack um angeforderten Platz vermindern
- ld SP,HL ; und den Platz reservieren
- ld B,H ; lokalen Stackframe-Pointer setzen
- ld C,L
- push BC ; auch in IX
- pop IX
- ex DE,HL ; HL = Returnadresse
- jp (HL) ; das war's - dort weitermachen
-
-
-
-
-
- ; +---------------------------------------------------------------------+
- ; | |
- ; | Funktionsausgang fuer Parameter/Locals, nach fentpl, der lokal |
- ; | benoetigte Platz wird zurueckgegeben, Platz in Bytes positiv als |
- ; | Parameter hinter Aufruf (16 Bit). |
- ; | |
- ; | Return : SP - um zurueckzugebenden Platz korrigiert |
- ; | BC, IX - alter Stackframe-Pointer (aufrufende Funktion) |
- ; | HL - bleibt (Returnwert der Funktion) |
- ; | A, DE - benutzt |
- ; | |
- ; +---------------------------------------------------------------------+
-
- public fextpl
- public ?exs
-
- fextpl:
- ?exs: ex DE,HL ; Returnwert der Funktion sichern
- pop HL ; Adresse Aufrufparam. (zurueckzugeb. Platz)
- ld A,(HL) ; LSB des zurueckzugebenden Platzes holen
- inc HL ; Zeiger auf MSB
- ld H,(HL) ; MSB holen
- ld L,A ; HL = 16-Bit Anzahl Bytes zureckzugeben
- add HL,SP ; = Anzahl Bytes Stack zu korrigieren
- ld SP,HL ; lokalen Platz deallokieren
- ex DE,HL ; restaurieren des Returnwertes der Funktion
- pop BC ; Stackframe-Pointer restaurieren
- pop IX ; sowie Indexregister (auch Stackframe-P.)
- ret ; das war's
-
-
- public ?inc
- public ?sxt
- public ?gf
- public ?g
- public ?sn
- public ?addhl
- public ?loc
- ?inc:
- ?sxt:
- ?gf:
- ?g:
- ?sn:
- ?addhl:
- ?loc: ret
-
- ;-----------------------------------------------------------------------
- ; SUPPORT.MAC
- ;-----------------------------------------------------------------------
- ;
- ; Z80 run time library
- ; DWP January 1995
- ;
- ; Modified DAR Jan 1995
- ; and routines in RST locations commented out
- ;
- ; Routines return TRUE or FALSE
- ;
- ; TRUE HL=1, Z flag clear ( NZ )
- ; FALSE HL=0 Z flag set
-
- .Z80
- public .nt
- ;-----------------------------------------------------------------------
- ; .nt ! (NOT) operator
- ; if( HL == 0 )
- ; return TRUE
- ; else
- ; return FALSE
-
- .nt: ld a,h
- or l
- jr z,.true
- jr .false
-
- ; public .eq,.ne
- ;-----------------------------------------------------------------------
- ; .eq .ne if( HL == DE ) or ( HL != DE )
- ; return TRUE
- ; else
- ; return FALSE
-
- ;.eq: xor a ; Clear carry
- ; sbc hl,de
- ; jr z,.true
- .false: xor a ; Clear carry (and A)
- ld h,a ; Set HL = 0;
- ld l,a
- ret
-
- ;.ne: xor a ; Clear carry
- ; sbc hl,de ; Compare
- ; jr z,.false
- .true: ld hl,1
- ld a,l
- or h
- ret
-
- public .le,.ge
- ;-----------------------------------------------------------------------
- ; .le .ge
- ; if( DE <= HL ) (DE >= HL )
- ; return TRUE
- ; else
- ; return FALSE
-
- .ge: ex de,hl ; swap registers
- .le: ld a,h ; Compare signs
- xor d
- jp m,.sdiff ; Skip if their different
- xor a ; They're the same, Clear carry
- sbc hl,de ; Compare them
- jr nc,.true ; TRUE if HL < DE
- jr .false ; else FALSE
- .gdiff:
- ex de,hl
- .sdiff:
- ld a,d ; Get sign of DE
- rlca ; ..to LSB
- and 1 ; Mask off
- ld l,a ; Set in HL and return
- ld h,0
- ret
-
- public .lt,.gt
- ;-----------------------------------------------------------------------
- ; .lt .gt
- ; if( DE < HL ) (DE > HL )
- ; return TRUE
- ; else
- ; return FALSE
-
- .lt: ex de,hl ; Swap values
- .gt: ld a,h ; Compare signs
- xor d
- jp m,.gdiff ; Skip if their different
- xor a ; They're the same, Clear carry
- sbc hl,de ; Compare them
- jr c,.true ; TRUE if HL < DE
- jr .false ; else FALSE
-
- public .ng
- ;-----------------------------------------------------------------------
- ; .ng Negate HL
-
- .ng: ld a,l
- cpl
- ld l,a
- ld a,h
- cpl
- ld h,a
- inc hl
- ld a,h
- or l
- ret
-
- ; public .sb
- ;-----------------------------------------------------------------------
- ; .sb
- ; return( DE-HL )
-
- ;.sb: ex de,hl
- ; or a
- ; sbc hl,de
- ; ret
-
- public .swt
- ;-----------------------------------------------------------------------
- ; .swt
- ; Switch table execution
- ; ld hl,<key>
- ; call .swt
- ; defw <# entries>
- ; defw <match>,<address>
- ; defw <match>,<address>
- ; ....
- ; defw <match>,<address>
- ; defw <address> (default value)
-
- .swt: ex de,hl ; Comparison value in DE
- pop hl ; address pointer to HL
- push bc ; Save BC
- ld c,(hl) ; BC = # entries in table
- inc hl
- ld b,(hl)
- inc bc ; Bump count by one
- dec hl
- swt.1: inc hl ; Point to table entry
- inc hl
- ld a,e ; Value to check for
- cpi ; Test ( Z on match, PO if BC=0)
- jp po,swt.def
- jr nz,swt.2 ; Skip if no match
- ld a,b ; ..else check hi byte
- cp (hl)
- swt.2: inc hl ; HL->address
- jr nz,swt.1 ; repeat if no match
- inc hl ; Matched on 2nd compare
- swt.def:
- ld a,(hl) ; Pick up address
- dec hl
- ld l,(hl)
- ld h,a
- pop bc ; reset BC
- jp (hl) ; Go to it
-
- public .ue,.uf
- ;-----------------------------------------------------------------------
- ; .ue (unsigned <=) .uf (unsigned >=)
- .uf: ex de,hl ; uge
- .ue: xor a ; Clear carry
- sbc hl,de ; Compare
- jr nc,.true ; TRUE if HL < DE
- jr .false ; else FALSE
-
- public .ul ;,.ug
- ;-----------------------------------------------------------------------
- ; .ul (unsigned < ) .ug (unsigned > )
-
- .ul: ex de,hl
- xor a
- ;.ug: xor a ; Clear Carry
- sbc hl,de
- jr c,.true
- jr .false
-
- public end_
- end_:
- end